package thread.mianshi.redPacket;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * Created by sj on 2018/7/12.
 */
public class Main {

    public static List<Float> redPackets = new ArrayList<Float>();
    public static void main(String[] args) throws InterruptedException {
        System.out.println("开始发红包.....");
        RedPacketUtil util = new RedPacketUtil();

        for (int i = 0;i< RedPacketUtil.RedPacket.ROB_RED_PACKET_COUT.getValue();i++) {
            RobRedPacketHandler.i = 0;
            System.out.printf("张三第%d次发红包红包个数为",i+1);
            //每次抢红包
            redPackets = util.splitRedPackets(RedPacketUtil.RedPacket.TOTAL_MONEY.getValue(), (int) RedPacketUtil.RedPacket.RED_PACKET_COUNT.getValue());
            System.out.println(redPackets);
            TimeUnit.SECONDS.sleep(1);


            ExecutorService executorService = Executors.newFixedThreadPool(RobRedPacketThread.peoples.size());
            for (int j = 0; j< RobRedPacketThread.peoples.size(); j++){
                RobRedPacketThread thread = RobRedPacketThread.peoples.get(j);
                executorService.execute(thread);
            }
            executorService.shutdown();
            TimeUnit.SECONDS.sleep(2);

        }


    }
}
